# A tibble: 4 × 2
trt pbo
<dbl> <dbl>
1 15 34
2 13 31
3 18 36
4 19 NA
2024-10-15
# A tibble: 4 × 2
trt pbo
<dbl> <dbl>
1 15 34
2 13 31
3 18 36
4 19 NA
# A tibble: 8 × 3
id result exposed
<int> <dbl> <chr>
1 1 45 n
2 2 43 n
3 3 48 n
4 4 49 n
5 1 64 y
6 2 61 y
7 3 66 y
8 4 62 y
alternative="two-sided"alternative="greater"alternative="less"var.equal=FALSE Henry Mann, PhD in Mathematics in 1935
Donald Ransom Whitney, PhD in Mathematics in 1946
Frank Wilcoxon, PhD in Chemistry, 1924
- X1: 34, 1695, 1193
- X2: 652, 11, 24, 16, 1543, 39
Group Outcome Rank
1 34 4
1 1695 9
1 1193 7
2 652 6
2 11 1
2 24 3
2 16 2
2 1543 8
2 39 5
652 11 24 16 1543 39
34 Loss Win Win Win Loss Loss
1695 Win Win Win Win Win Win
1193 Win Win Win Win Loss Win
1,2,3 1,2,4 1,2,5 1,2,6 1,2,7 1,2,8 1,2,9
1,3,4 1,3,5 1,3,6 1,3,7 1,3,8 1,3,9 1,4,5
1,4,6 1,4,7 1,4,8 1,4,9 1,5,6 1,5,7 1,5,8
1,5,9 1,6,7 1,6,8 1,6,9 1,7,8 1,7,9 1,8,9
2,3,4 2,3,5 2,3,6 2,3,7 2,3,8 2,3,9 2,4,5
2,4,6 2,4,7 2,4,8 2,4,9 2,5,6 2,5,7 2,5,8
2,5,9 2,6,7 2,6,8 2,6,9 2,7,8 2,7,9 2,8,9
3,4,5 3,4,6 3,4,7 3,4,8 3,4,9 3,5,6 3,5,7
3,5,8 3,5,9 3,6,7 3,6,8 3,6,9 3,7,8 3,7,9
3,8,9 4,5,6 4,5,7 4,5,8 4,5,9 4,6,7 4,6,8
4,6,9 4,7,8 4,7,9 4,8,9 5,6,7 5,6,8 5,6,9
5,7,8 5,7,9 5,8,9 6,7,8 6,7,9 6,8,9 7,8,9
6: 1,2,3
7: 1,2,4
8: 1,2,5 1,3,4
9: 1,2,6 1,3,5 2,3,4
10: 1,2,7 1,3,6 1,4,5 2,3,5
11: 1,2,8 1,3,7 1,4,6 2,3,6 2,4,5
12: 1,2,9 1,3,8 1,4,7 1,5,6 2,3,7 2,4,6 3,4,5
13: 1,3,9 1,4,8 1,5,7 2,3,8 2,4,7 2,5,6 3,4,6
14: 1,4,9 1,5,8 1,6,7 2,3,9 2,4,8 2,5,7 3,4,7 3,5,6
15: 1,5,9 1,6,8 2,4,9 2,5,8 2,6,7 3,4,8 3,5,7 4,5,6
16: 1,6,9 1,7,8 2,5,9 2,6,8 3,4,9 3,5,8 3,6,7 4,5,7
17: 1,7,9 2,6,9 2,7,8 3,5,9 3,6,8 4,5,8 4,6,7
18: 1,8,9 2,7,9 3,6,9 3,7,8 4,5,9 4,6,8 5,6,7
19: 2,8,9 3,7,9 4,6,9 4,7,8 5,6,8
20: 3,8,9 4,7,9 5,6,9 5,7,8
21: 4,8,9 5,7,9 6,7,8
22: 5,8,9 6,7,9
23: 6,8,9
24: 7,8,9
data_dictionary: postural-sway.txt
copyright: |
Permission is granted to freely use material on the OzDASL site, although acknowledgement of the OzDASL site as the data source would be appreciated. Please be aware though that some of the OzData data sets were originally published elsewhere; original sources are cited on the description page. If you intend to re-publish one of these data sets it may be necessary to obtain permission from the original copyright holder.
description: |
Postural sway is a measure of how well patients can balance. The postural sway was measured using a force plate in two groups of subjects, elderly or young. Sway was measured in the forward/back direction and in the side-to-side direction.
additional_description: https://gksmyth.github.io/ozdasl/general/balaconc.html
download_url: https://gksmyth.github.io/ozdasl/general/balaconc.txt
format: tab delimited
varnames: Included in the first line
missing_value_code: not needed
size:
rows: 17
columns: 3
Age:
scale: nominal
values:
- Elderly
- Young
FBSway:
label: Sway in the forward-backward direction
scale: ratio
range: positive real
SideSway:
label: Sway in the side-to-side direction
scale: ratio
range: positive real
---
title: "Alternative analysis of postural sway data"
format:
html:
embed-resources: true
---
This program runs some alternatives to the two-sample t-test. Consult the [data dictionary][dic] for information about the data itself.
[dic]: https://github.com/pmean/data/blob/main/files/postural-sway.yaml
This program was written by Steve Simon on 2024-10-13. It is placed in the public domain.
## Libraries
```{r setup}
#| message: false
#| warning: false
library(tidyverse)
```
## Read data
```{r read-sway}
sway <- read_tsv(
file="../data/postural-sway.txt",
col_types="cnn")
names(sway) <- tolower(names(sway))
glimpse(sway)
```
## Boxplot of front-to-back sway by age
```{r boxplot-1}
#| fig.height: 2
#| fig.width: 6
sway |>
ggplot(aes(age, fbsway)) +
geom_boxplot() +
ggtitle("Graph drawn by Steve Simon on 2024-10-13") +
xlab("Treatment group") +
ylab("Front to back sway") +
coord_flip()
```
The outlier causes some concern about the validity of the two-sample t-test.
## Descriptive statistics for front-to-back sway by age
```{r group-means}
sway |>
group_by(age) |>
summarize(
fb_mn=mean(fbsway),
fb_sd=sd(fbsway),
n=n())
```
In addition to the outlier, notice that the group with the larger mean (elderly) has the larger standard deviation. This indicates that a log transformation may produce better results.
## Log transformation, 1
```{r log-transform-1}
sway |>
mutate(log_fbsway=log10(fbsway)) -> log_sway
```
## Log transformation, 2
```{r log-transform-2}
#| fig.height: 2
#| fig.width: 6
log_sway |>
ggplot(aes(age, log_fbsway)) +
geom_boxplot() +
ggtitle("Graph drawn by Steve Simon on 2024-10-13") +
xlab("Treatment group") +
ylab("Front to back sway") +
coord_flip()
```
There are no outliers after a log transformation.
## Log transformation, 3
```{r compare-means-on-log-scale}
log_sway |>
group_by(age) |>
summarize(
log_mn=mean(log_fbsway),
log_sd=sd(log_fbsway),
n=n())
```
The standard deviations on the log scale are quite a bit more similar than they were on the original scale.
## Two-sample t-test using the log transformation
```{r t-test}
m2 <- t.test(
log_fbsway ~ age,
data=log_sway,
alternative="two.sided",
var.equal=TRUE)
m2
```
There is a statistically significant difference between the log front-to-back sway between elderly patients and young patients. The confidence interval will be interpreted after transforming back to the original scale of measurement.
## Back-transform confidence interval to the original scale.
```{r back-transform}
10^(m2$conf.int)
```
We are 95% confident that the geometric mean front-to-back sway in elderly patients is somewhere between 1.24 times higher and 8 times higher than the geometric mean for young patients. This indicates a statistically significantly higher mean for elderly patients. The confidence interval is still very wide, indicating a lot of sampling error in these two small samples.
## Mann-Whitney-Wilcoxon
```{r nonparametric-test}
wilcox.test(fbsway ~ age, data=sway)
```
Since the p-value is small, you would reject the null hypothesis and conclude that there is a statistically significant difference in front-to-back sway values between elderly and young patients.
---
title: "Alternative analysis of postural sway data"
format:
html:
embed-resources: true
---
This program runs a paired t-test. Consult the [data dictionary][dic] for information about the data itself.
[dic]: https://github.com/pmean/data/blob/main/files/postural-sway.yaml
This program was written by Steve Simon on 2024-10-15. It is placed in the public domain.
## Libraries
```{r setup}
#| message: false
#| warning: false
library(tidyverse)
```
## Read data
```{r read-sway}
sway <- read_tsv(
file="../data/postural-sway.txt",
col_types="cnn")
names(sway) <- tolower(names(sway))
glimpse(sway)
```
## Paired t-test
The research team is also interested in whether the front-to-back sway is larger than the side-to-side sway, combining both the elderly and young patients into one group.
## Compute and graph differences
```{r compute-difference-1}
sway |>
mutate(diff_sway=fbsway-sidesway) -> paired_differences
paired_differences |>
summarize(
diff_mn=mean(diff_sway),
diff_sd=sd(diff_sway))
```
The average difference is positive, indicating that front-to-back-sways are larger on average. The standard deviation of the differences is large.
## Boxplot of differences
```{r compute-difference-2}
#| fig.height: 1.5
#| fig.width: 6
paired_differences |>
ggplot(aes(diff_sway, "Combined")) +
geom_boxplot() +
ggtitle("Graph drawn by Steve Simon on 2024-10-13") +
xlab("Front-to-back sway minus side-to-side sway") +
ylab(" ")
```
More than 75% of the differences are positive, also indicating that front-to-back sways tend to be larger.
## Paired t-test
```{r paired-t-test}
t.test(
sway$fbsway,
sway$sidesway,
paired=TRUE,
alternative="two.sided")
```
The p-value is small, indicating that front-to-back sways are significantly larger than side-to-side sways. The 95% confidence intervals shows that the mean difference is at least 0.21 units larger for front-to-back sway and possibly as large as 7.0 units.
---
title: "Directions for 5501-08 programming assignment"
format:
html:
embed-resources: true
---
This programming assignment was written by Steve Simon on 2024-10-08 and is placed in the public domain.
## Program
- Download the [program][tem]
- Store it in your src folder
- Modify the file name
- Use your last name instead of "simon"
- Modify the documentation header
- Add your name to the author field
- Optional: change the copyright statement
[tem]: https://github.com/pmean/classes/blob/master/biostats-1/09/src/simon-5501-09-sway.qmd
## Data
- Download the [data][dat] file
- Store it in your data folder
- Refer to the [data dictionary][dic], if needed.
[dat]: https://github.com/pmean/data/blob/main/files/postural-sway.txt
[dic]: https://github.com/pmean/data/blob/main/files/postural-sway.yaml
## Question 1
The side-to-side sway data appears to have a pair of outliers and some evidence of heterogenity. Use a log transformation to see if this makes things better. Analyze the data on a log scale using a two-sample t-test and report the confidence interval after transforming back to the original scale of measurement.
## Question 2
You want to replicate these findings in a new population, using the log transformation on the new data. Select a standard deviation from log transformed side-to-side sway values in the current study (go halfway between the two standard deviations). You want to have 90% power for detecting a 1.5 fold change (which is 0.176 units on a log base 10 scale). If you use a two-sided hypothesis with alpha = 0.05, what sample size would you need?
## Your submission
- Save the output in html format
- Convert it to pdf format.
- Make sure that the pdf file includes
- Your last name
- The number of this course
- The number of this module
- Upload the file
## If it doesn't work
Please review the [suggestions if you encounter an error page][sim3].
[sim3]: https://github.com/pmean/classes/blob/master/general/suggestions-if-you-encounter-an-error.md